package cn.zz.veggie.web.controller.mgmt;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.zz.comm.core.types.query.PageQuery;
import cn.zz.comm.types.result.P;
import cn.zz.comm.web.annotation.BoxRespResult;
import cn.zz.veggie.application.service.SettleAppService;
import cn.zz.veggie.web.types.dto.mgmt.settle.MgmtSettleCreateDto;
import cn.zz.veggie.web.types.dto.mgmt.settle.MgmtSettleQueryDto;
import cn.zz.veggie.web.types.vo.mgmt.MgmtSettleVo;
import jakarta.validation.constraints.Positive;
import lombok.RequiredArgsConstructor;

/**
 * 
 * 管理端/结算管理
 * 
 * @author zhongq
 * @since 2024/6/7
 */
@Validated
@BoxRespResult
@RestController
@RequiredArgsConstructor
@RequestMapping("/mgmt/settle")
public class MgmtSettleController {
	private final SettleAppService settleAppService;

	/**
	 * 结算列表
	 */
	@GetMapping("/list")
	public P<MgmtSettleVo> list(@Validated MgmtSettleQueryDto dto,
			@RequestParam(defaultValue = "1") @Positive Integer current,
			@RequestParam(defaultValue = "10") @Positive Integer size) {
		return settleAppService.mgmtGetList(dto, PageQuery.of(current, size));
	}

	/**
	 * 刷新统计
	 */
	@PutMapping("/refresh")
	public void refresh(@RequestParam @Positive Integer id) {
		settleAppService.adminRefresh(id);
	}

	/**
	 * 创建 采购统计
	 */
	@PostMapping("/create")
	public void create(@RequestBody @Validated MgmtSettleCreateDto dto) {
		dto.requireValid();
		settleAppService.mgmtCreateSettle(dto);
	}

	/**
	 * 标记已结算
	 */

	// @PutMapping("/complete")
	public void complete(@RequestParam @Positive Integer id) {
		settleAppService.adminMarkComplete(id);
	}
}